function Block(ctx, x, y) {
    this.w = 50;
    this.h = 20;
    this.disappeared = false;

    this.x = x;
    this.y = y;
    this.ctx = ctx;
}

Block.prototype.draw = function() {
    if(!this.disappeared) {
        ctx.fillStyle = "#e58d7f";
        ctx.fillRect(this.x, this.y, this.w, this.h);

        ctx.strokeStyle = "white";
        ctx.strokeRect(this.x, this.y, this.w, this.h);
    }
};

Block.prototype.solveCollision = function(ball) {
    var r = ball.r;
    var bx = ball.x;
    var by = ball.y;

    if(this.disappeared) return;

    if((bx >= this.x) && (bx <= this.x + this.w)) {
        if((this.y > by && this.y - by <= r) || (this.y < by && by - r <= this.y + this.h)) {
        
            ball.speedY = -ball.speedY;

            this.disappeared = true;
        }    
    } else {
        var dist;
        if(bx > this.x + this.w) {
            dist = Math.sqrt(Math.pow((bx - this.x - this.w),2) + Math.pow((by - this.y),2));
        } else {
            dist = Math.sqrt(Math.pow((bx - this.x),2) + Math.pow((by - this.y),2));
        }

        if(dist <= r) {   
     
            ball.speedY = -ball.speedY;
            ball.speedX = -ball.speedX;
            
            this.disappeared = true;
        }
    }
};